package com.rickie.pvuv;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 将时间戳转换为指定格式日期
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        // 获取当前时间戳 -- 如 1638410263503， 1638275127201
        long timestamp1 = System.currentTimeMillis();
        System.out.println("时间戳："  + timestamp1);
        System.out.println(timestamp2Date(timestamp1, ""));
        //System.out.println(timestamp2Date(timestamp1/1000, ""));
    }

    public static String timestamp2Date(long timestamp, String format){
        if(format == null || format.length()<=0) {
            format = "yyyy-MM-dd HH:mm:ss";
        }
        return new SimpleDateFormat(format, Locale.CHINA).format(new Date(timestamp));
    }
}
